#include "guanqiachoose.h"
#include "ui_guanqiachoose.h"

guanQiaChoose::guanQiaChoose(Widget * mainWidget, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::guanQiaChoose)
{
    ui->setupUi(this);

    this->mainWidget = mainWidget; //接收主窗口
    this->play = new QSound(GAME_BGM_GAME_MENU);
    this->initScene(); //初始化窗口

    pix.load(CHOOSE_);
}

guanQiaChoose::~guanQiaChoose()
{
    delete ui;
}

void guanQiaChoose::on_guanQia1_clicked()
{
    this->mainWidget->guanQia = 1; //修改关卡数
    this->play->stop();
    this->hide(); //隐藏当前窗口
    emit this->sendMoShi();
    Widget::score = 0;
    this->mainWidget->show(); //显示主窗口
    //this->mainWidget->playGame();
}

void guanQiaChoose::on_guanQia2_clicked()
{
    if(Widget::flag1 == 1){ //如果解锁
        this->mainWidget->guanQia = 2; //修改关卡数
        this->play->stop();
        this->hide(); //隐藏当前窗口
        emit this->sendMoShi();
        Widget::score = 0;
        this->mainWidget->show(); //显示主窗口
        //this->mainWidget->playGame();
    }else{
        QMessageBox::warning(NULL, GAME_NAME, "分数大于等于3才能解锁此关卡！");
    }
}

void guanQiaChoose::on_guanQia3_clicked()
{
    if(Widget::flag2 == 1){ //如果解锁
        this->mainWidget->guanQia = 3; //修改关卡数
        this->play->stop();
        this->hide(); //隐藏当前窗口
        emit this->sendMoShi();
        this->mainWidget->show(); //显示主窗口
        //this->mainWidget->playGame();
    }else{
        QMessageBox::warning(NULL, GAME_NAME, "分数大于等于5才能解锁此关卡！");
    }

}

//初始化窗口
void guanQiaChoose::initScene(){
    setWindowTitle(GAME_NAME); //设置窗口名称
    setWindowIcon(QIcon(GAME_ICON_)); //设置窗口图标
    setFixedSize(1000,600);
        ui->guanQia1->setIconSize(QSize(100,100));
        ui->guanQia1->setIcon(QIcon(CHOOSE_PIX1));
        ui->guanQia1->setStyleSheet("QPushButton{background-color:rgba(0,0,0,0);}");
        ui->guanQia2->setIconSize(QSize(100,100));
        ui->guanQia2->setIcon(QIcon(CHOOSE_PIX2));
        ui->guanQia2->setStyleSheet("QPushButton{background-color:rgba(0,0,0,0);}");
        ui->guanQia3->setIconSize(QSize(100,100));
        ui->guanQia3->setIcon(QIcon(CHOOSE_PIX3));
        ui->guanQia3->setStyleSheet("QPushButton{background-color:rgba(0,0,0,0);}");

}

void guanQiaChoose::paintEvent(QPaintEvent *event){
      QPainter painter(this);
      painter.drawPixmap(0,0,pix);
}

void guanQiaChoose::recScore(int score){
    this->score = score;
}
